<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    /**
     * 1、面向对象三大特性：封装、继承、多态
     * 继承：1、减少重复的代码(将公共的代码抽取到父类中，字类继承父类)   2、多态的前提（鸭子类型）
     * */

     class Person {
      constructor(name, age){
        this.name = name
        this.age = age
      }
      running(){
        console.log('running');
      }
     }


    //  使用继承实现Student类和Teacher类
    class Student extends Person {
      constructor(name, age, sno) {
        // 子类中必须初始化父类对象
        super(name, age) // super调用父类的构造方法，并将参数传入，初始化父类中的属性
        this.sno = sno
      }
    }
    
    
    class Teacher extends Person {
      constructor(name, age, title) {
        super(name, age)
        this.title = title
      }
    }

    const stu = new Student('plum', 16, '133')
    console.log(stu.name, stu.age, stu.sno);
    stu.running()
    
    const teacher = new Teacher('plum1', 16, '教授')
    console.log(teacher.name, teacher.age, teacher.title);
    teacher.running()

    //  class Student {
    //   constructor(name, age, sno){
    //     this.name = name
    //     this.age = age
    //     this.sno = sno
    //   }
    //   running(){
    //     console.log('running');
    //   }
    //  }


    //  class Teacher {
    //   constructor(name, age, title){
    //     this.name = name
    //     this.age = age
    //     this.title = title
    //   }
    //   running(){
    //     console.log('running');
    //   }
    //  }


  </script>
</body>
</html>